找传奇、传世资源到传世资源站!

C# 进程监测及执行(进程保活)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

当程序打开后 监测进程是否在执行,如果没有执行将自动打开启动路径对应的文件,详见下图
from clipboard
using System;using System.Diagnostics;using System.Drawing;using System.IO;using System.Linq;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using System.Windows.Forms;namespace 进程监测及自动执行{ public partial class Main : Form { public string t1, t2; public int i = 0; public Main() { InitializeComponent(); t1 = System.Configuration.ConfigurationManager.AppSettings["ProcessName"]; t2 = System.Configuration.ConfigurationManager.AppSettings["ProcessPath"]; textBox1.Text = t1; textBox2.Text = t2; } private void timer1_Tick(object sender, EventArgs e) { if (Process.GetProcessesByName(t1).ToList().Count > 0) { //存在 } else { Process mProcess = new Process(); mProcess.StartInfo.FileName = t2; mProcess.StartInfo.WorkingDirectory = t2.Substring(0, t2.LastIndexOf("\\")); mProcess.Start(); } } } }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复